package br.com.gaspar.academia.mb;


import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;

import br.com.gaspar.academia.bo.iface.IContatoBO;
import br.com.gaspar.academia.modelo.Contato;
import br.com.gaspar.framework.visao.jsf.ManagedBeanBase;
import br.com.gaspar.utils.exception.BaseException;

@ManagedBean(name="ContatoMB")
@RequestScoped
public class ContatoMB extends ManagedBeanBase<Contato> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	@EJB
	private IContatoBO bo;
	
		
	@Override
	protected IContatoBO getFachada() {
		return bo;
	}
	
	@PostConstruct
	@Override
	public void iniciar() {
		setEntidade(new Contato());
		super.iniciar();
	}
	
	@Override
	protected void criarAntes() throws BaseException {
		setEntidade(new Contato());
		super.criarAntes();
	}
	
	public void gravarContato(ActionEvent actionEvent) {  
		super.gravar();
		FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO,
				"E-mail enviado com sucesso!!", null);
		FacesContext.getCurrentInstance().addMessage(null, message);  
	}
	
	@Override
	protected void gravarApos() throws BaseException {
		setEntidade(null);
	}
}
